﻿using ConfExpert.Forms.Base;
using DevExpress.XtraPivotGrid;
using DevTeam;

using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class TopAdetleri : XForm
    {
        public TopAdetleri()
        {
            InitializeComponent();
        }

        BindingSource bs;

        private void TopAdetleri_Load(object sender, EventArgs e)
        {
            
            DataTable dt = ExecuteDataTable("GetRollCount");
            dt.TableName = "RollCount";
            ds.Tables.Add(dt);
            bs = new BindingSource(ds, "RollCount");

            DrillDownGrid(gvArtikel, bs);
            gvArtikel.MakeColumnInvisible("CustomerId", "TopSayisi");
            InitPivot(pgcTopAdetleri, bs);

            splitContainerControl1.AutoSize();
            ExpandCollapse(splitContainerControl1, AcKapa.Collapse);
        }

        void InitPivot(PivotGridControl pgc, BindingSource bs)
        {
            pgc.DataSource = bs;

            pgc.BeginUpdate();
            AddNewField(pgc, "CustomerId", PivotArea.RowArea).FieldEdit = RI(Rp.V_Customer);
            pgc.FieldValueDisplayText += new PivotFieldDisplayTextEventHandler(pivotGrid_FieldValueDisplayText);

            AddNewField(pgc, "TopSayisi", PivotArea.ColumnArea);
            PivotGridField fld = AddNewField(pgc, "ProductId", PivotArea.DataArea);
            fld.Caption = "Artikel Sayısı";
            fld.SummaryType = DevExpress.Data.PivotGrid.PivotSummaryType.Count;

            pgc.EndUpdate();
            pgc.BestFit();
        }

        private void pgcTopAdetleri_CellClick(object sender, PivotCellEventArgs e)
        {
            gcArtikel.DataSource = e.CreateDrillDownDataSource();
            ExpandCollapse(splitContainerControl1, (gvArtikel.RowCount > 0 ? AcKapa.Expand : AcKapa.Collapse));
            gvArtikel.BestFitColumns();
        }
    }
}
